package com.dhy.controller;

import com.dhy.pojo.relation_pojo.EmployeeAndRole;
import com.dhy.service.IEmployeeAndRoleService;
import com.dhy.utils.AjaxResult;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("employeeAndRoles")
@CrossOrigin
public class EmployeeAndRoleController extends BaseController<EmployeeAndRole> {

    @Autowired
    IEmployeeAndRoleService iEmployeeAndRoleService;

    @GetMapping("RoleId/{roleId}")
    public AjaxResult selectByRoleId(@PathVariable("roleId") Long roleId) {
        AjaxResult ajaxResult = AjaxResult.ajaxResultBuild();
        try {
            List<EmployeeAndRole> employeeAndRoles = iEmployeeAndRoleService.selectByRoleId(roleId);
            ajaxResult.setMessage("操作成功").setSuccess(true).setData(employeeAndRoles);
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult.setMessage("操作失败").setSuccess(false);
        }
        return ajaxResult;
    }
}
